set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_CONTACT "${PROJECT_MAINTAINER}")
set(CPACK_PACKAGE_VERSION ${iowow_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${iowow_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${iowow_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${iowow_VERSION_PATCH})
set(CPACK_PACKAGE_VENDOR ${PROJECT_VENDOR})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION_SUMMARY})
set(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_BUILD_TYPE}-${CMAKE_SYSTEM_NAME}-${PROJECT_ARCH}")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
    set(CPACK_STRIP_FILES ON)
endif()

if (PACKAGE_DEB)
	execute_process (
	  COMMAND          /usr/bin/dpkg --print-architecture
	  OUTPUT_VARIABLE  CPACK_DEBIAN_PACKAGE_ARCHITECTURE
	  RESULT_VARIABLE  EXECUTE_RESULT
	  OUTPUT_STRIP_TRAILING_WHITESPACE
	  ERROR_QUIET
	)
	if (EXECUTE_RESULT)
	  message(FATAL_ERROR "dpkg not found: No package generation.")
	endif()
	set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
	set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PROJECT_WEBSITE})
	set(CPACK_DEBIAN_PACKAGE_SECTION libs)
	set(CPACK_DEBIAN_PACKAGE_PRIORITY optional)
	#set(CPACK_DEBIAN_PACKAGE_DEPENDS zlib1g)
	set(CPACK_DEBIAN_PACKAGE_BUILD_DEPENDS pkg-config git devscripts dh-make)
    if (NOT PPA_DEBIAN_VERSION)
        set(PPA_DEBIAN_VERSION ppa1)
    endif()
	if (PROJECT_PPA)
		set(DPUT_HOST ${PROJECT_PPA})
	endif()
	#set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "any")
	set(CPACK_DEBIAN_RESOURCE_FILE_CHANGELOG ${CMAKE_SOURCE_DIR}/Changelog)
	set(CPACK_DEBIAN_UPDATE_CHANGELOG ON)
endif(PACKAGE_DEB)

if (PACKAGE_TGZ)
    set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
endif(PACKAGE_TGZ)

include(CPack)

if (ENABLE_PPA)
    if (NOT PROJECT_PPA_DISTRIB_TARGET)
        set(PROJECT_PPA_DISTRIB_TARGET xenial bionic)
    endif()
    set(DPUT_CONFIG_IN ${CMAKE_CURRENT_SOURCE_DIR}/debian/dput.cf.in)
    include(UploadPPA)
endif()
